﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;

public partial class Control_index_fangan : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData(3, rpFamily);
            BindData(4, rpCompany);
        }
    }
    protected void BindData(int labelID, Repeater rp)
    {
        MatchIns.BLL.TCategory bll = new MatchIns.BLL.TCategory();
        MatchIns.BLL.PageInfo pi = new MatchIns.BLL.PageInfo(int.MaxValue, 1);
        pi.Where = " where labelid="+labelID.ToString();
        pi.OrderBy = " order by sort desc";
        List<MatchIns.Model.TCategory> ds = new List<MatchIns.Model.TCategory>();
        ds = bll.GetPageList(pi).List;
        List<MatchIns.Model.TCategory> bigCategory = ds.FindAll(delegate(MatchIns.Model.TCategory d) { return d.ParentID == 0; });
        rp.DataSource = bigCategory;
        rp.DataBind();
    }
    protected void rpFamily_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            MatchIns.Model.TCategory model =e.Item.DataItem as MatchIns.Model.TCategory;
            int bigCategoryID = model.CategoryID;
            MatchIns.BLL.TCategory bll = new MatchIns.BLL.TCategory();
            MatchIns.BLL.PageInfo pi = new MatchIns.BLL.PageInfo(int.MaxValue, 1);
            pi.Where = " where labelid=3";
            pi.OrderBy = " order by sort desc";
            List<MatchIns.Model.TCategory> ds = new List<MatchIns.Model.TCategory>();
            ds = bll.GetPageList(pi).List;
            List<MatchIns.Model.TCategory> bigCategory =
                ds.FindAll(delegate(MatchIns.Model.TCategory d) { return d.ParentID == model.CategoryID; });
            Repeater rp = e.Item.FindControl("rpItems") as Repeater;
            rp.DataSource = bigCategory;
            rp.DataBind();
        }
    }
    protected void rpCompany_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            MatchIns.Model.TCategory model = e.Item.DataItem as MatchIns.Model.TCategory;
            int bigCategoryID = model.CategoryID;
            MatchIns.BLL.TCategory bll = new MatchIns.BLL.TCategory();
            MatchIns.BLL.PageInfo pi = new MatchIns.BLL.PageInfo(int.MaxValue, 1);
            pi.Where = " where labelid=4";
            pi.OrderBy = " order by sort desc";
            List<MatchIns.Model.TCategory> ds = new List<MatchIns.Model.TCategory>();
            ds = bll.GetPageList(pi).List;
            List<MatchIns.Model.TCategory> bigCategory =
                ds.FindAll(delegate(MatchIns.Model.TCategory d) { return d.ParentID == model.CategoryID; });
            Repeater rp = e.Item.FindControl("rpItems") as Repeater;
            rp.DataSource = bigCategory;
            rp.DataBind();
        }
    }
}